#include "stdafx.h"
#include "td_enemy.h"
#include "td_resource.h"

td_enemy::td_enemy()
{
	xy_enemy.x = 0;
	xy_enemy.y = 0;
}
td_enemy::~td_enemy()
{
}
CvPoint td_enemy::get_xy()
{
	return xy_enemy;
}
void td_enemy::move_enemy(IplImage *background,int a)
{
	if (hp_enemy == 0)return;
	if ( xy_enemy.x >= 630 || xy_enemy.y >= 630)
	{
		return;
	}
	if (dir_enemy == 1)
	{
		xy_enemy.y = xy_enemy.y - speed_enemy;
	}
	else if (dir_enemy == 2)
	{
		xy_enemy.x = xy_enemy.x - speed_enemy;
	}
	else if (dir_enemy == 3)
	{
		xy_enemy.y = xy_enemy.y + speed_enemy;
	}
	else
	{
		xy_enemy.x = xy_enemy.x + speed_enemy;
	}
	cvLine(background, CvPoint(xy_enemy.y + 10, xy_enemy.x + 3),
		CvPoint(xy_enemy.y + 10 + hp_enemy, xy_enemy.x + 3), CvScalar(0, 0, 255), 3);
	for (int i = 0;i < 70;i++)
	{
		for (int j = 0;j < 70;j++)
		{
			if (CV_IMAGE_ELEM(bing1[a%10], uchar, i, j * 3 + 0) < 250 &&
				CV_IMAGE_ELEM(bing1[a%10], uchar, i, j * 3 + 1) < 250 &&
				CV_IMAGE_ELEM(bing1[a%10], uchar, i, j * 3 + 2) < 250)
			{
				CV_IMAGE_ELEM(background, uchar, i + xy_enemy.x, (j + xy_enemy.y) * 3 + 0) =
					CV_IMAGE_ELEM(bing1[a%10], uchar, i, j * 3 + 0);
				CV_IMAGE_ELEM(background, uchar, i + xy_enemy.x, (j + xy_enemy.y) * 3 + 1) =
					CV_IMAGE_ELEM(bing1[a%10], uchar, i, j * 3 + 1);
				CV_IMAGE_ELEM(background, uchar, i + xy_enemy.x, (j + xy_enemy.y) * 3 + 2) =
					CV_IMAGE_ELEM(bing1[a%10], uchar, i, j * 3 + 2);
			}
		}
	}
}
void td_enemy::input_enemy1(IplImage **one,IplImage **two)
{
	bing1 = one;
	bing2 = two;
}

